<template>
	<view>
		<view class="cancle-container">
			<c-layout>
				<c-navigation-bar slot="head" :title="$t('orderDetails.applicant')"></c-navigation-bar>

				<view class="goodsInfo">
					<view class="productBox">
						<view class="productBox_top">
							<view class="productBox-img">
								<u-image
									:src="$u.file.getMedieUrl(goodsDetail.image)"
									style="height: 160rpx; width: 160rpx"
								></u-image>
								<view class="middle-box">
									<uni-tooltip :content=" goodsDetail.name">
										<view class="productBox-tittle">
											{{  goodsDetail.name }}
										</view>
									</uni-tooltip>
									<uni-tooltip :content="goodsDetail.goodsDesc ">
										<view class="productBox-introl">
											{{  goodsDetail.goodsDesc}}
										</view>
									</uni-tooltip>
									<view class="number-box">
										<view class="productBox-price">${{ goodsDetail.money  }}</view>

										<view class="productBox-num">X{{  goodsDetail.num }}</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>

				<view class="cancle-box">
					<view class="select" v-if="type == 0">
						<view class="">							
							<view class="tittle1">{{$t('orderDetails.enterTracking')}}</view>
							<view class="fill-number" >							
								<u-input @input="inputChange"  v-model="value" :type="number" :border="border" :placeholder="placeholder" border-color="#D2D2D2"  height="96"/>
								<!-- <uni-icons type="search" color="#ccc" size="24"></uni-icons> -->
								<button class="mini-btn" type="default" size="mini" @click="handleSearch" style="width: 100rpx;height: 60rpx;margin-left: 20rpx;" >search</button>
							</view>
						<view class="" v-if="placeholder2">
							<view class="tittle1">{{$t('orderDetails.logistics_company')}}：</view>
							<u-input    :v-model="company" :type="number" :border="border" :disabled="true" :placeholder="placeholder2" border-color="#D2D2D2"  height="96"/>
						</view>
						
						</view>
					</view>
					<view class="select" v-else>
						<view class="tittle1">{{$t('orderDetails.trackingNumber')}}</view>
						<u-input  v-model="value" :type="number" :border="border"  :placeholder="placeholder" border-color="#D2D2D2"  height="96" disabled/>
						<view class="" v-if="placeholder2">
							<view class="tittle1">{{$t('orderDetails.logistics_company')}}：</view>
							<u-input   v-model="company" :type="number" :border="border" :disabled="true" :placeholder="placeholder2" border-color="#D2D2D2"  height="96"/>
						</view>
						
					</view>
					<!-- <view class="">
						<view class="tittle1">Refund amount</view>
						<view class="select-amount">Cannot be modified, at most ${{ goodsDetail.money }}</view>
					</view> -->
					<!-- 退货/退款状态 -->
					<!-- <view class="popop-box1">
						<view class="">
							{{$t('orderDetails.severType')}}
						</view>
					</view>
					<view class="check-box">
						<uni-data-checkbox 
						v-model="value2" 
						:localdata="range2" 
						@change="change2"
						:multiple="false"
						selectedColor="#1E2432"
						:disabled="true"
						class="check-item"
						></uni-data-checkbox>
					</view> -->
					
					<button class="control-button" v-if="goodsDetail.returnInfo.status==4" type="default" @click="openModal">{{$t('orderDetails.confirmReceipt') }}</button>
					<button class="control-button" v-else  type="default" :disabled="type==1" @click="goOkPage">{{$t('system.Submit') }}</button>
					<inputPayPassword @finish="payPwdPopFinish" :payPwdPopShow.sync="payPwdPopShow" :maxlength="6"></inputPayPassword>
				</view>

				<view>
					<u-toast ref="uToast" />
				</view>
			</c-layout>
		</view>
	</view>
</template>

<script>
import { values } from '../../static/js/cos-wx-sdk-v5';
export default {
	data() {
		return {
			placeholder2:null,
			company:null,
			payPwdPopShow:false,
			password:null,//确认收货密码
			value2:1,//退换货状态  默认为退货
			range2: [{"value": 1,"text":this.$t('orderDetails.Return')	},{"value": 2,"text": this.$t('orderDetails.exchange')},{"value": 3,"text":this.$t('orderDetails.forRefund')}],
			placeholder:"",
			number:"text",
			border:true,
			appBaseUrl: process.uniEnv.COSHost,
			type: null,
			//请求参数
			parmasData: {},
			value: null,
			content: '',
			goodsDetail: {
				price: 198,
				name: 'Roller Rabbit',
				order: '3324502349KJD2343',
				image: '',
				by: 'Black Heart Institution',
				intro: 'Realize Syirian children',
				qty: '1'
			}
		};
	},
	methods: {
		inputChange(event){
			console.log(event.detail);
			this.placeholder2=null
		},
		
		handleSearch(){
			console.log('this.placeholder',this.placeholder);
			if(!this.value && !this.placeholder){
				this.showToast(this.$t('orderDetails.cannotEmpty'))
				return
			}
			let parmas=this.value?this.value:this.placeholder
			this.$u.get(`/app/express/inquireCourierCompany/${parmas}`).then((r) => {
				if (r.code == 200) {
					if(r.data =="null"){
						this.placeholder2=this.$t('orderDetails.other_logistics_company')
					}else{
						this.placeholder2=r.data
					}
				}
			})	
		},
		getTrackNumber(){
			this.$u.get(`/app/shopOrderReturnApproved/express/${this.goodsDetail.returnInfo.id}`).then((r) => {
				if (r.code == 200) {
					this.placeholder=r.data.expressNum	
				}
			})	
		},
		goOkPage() {	
		
			if(!this.value){
				this.showToast(this.$t('orderDetails.cannotEmpty'))
			}else if(!this.placeholder2){
				this.showToast(this.$t('orderDetails.searchPakage'))
			}
			else{
				let data={
					approvedId:this.goodsDetail.returnInfo.id,
					expressNum:this.value,
				}
				this.$u.post(`/app/shopOrderReturnApproved/returnShipped`,data).then((r) => {
					if (r.code == 200) {
						this.showToast(this.$t('orderDetails.applaySucs'),"/pages/order/myOrder")
					}
				})				
			}
		},
		confirmReceipt(){		
			let data={
				approvedId:this.goodsDetail.returnInfo.id,
			}
			this.$u.post(`/app/shopOrderReturnApproved/returnReceived`,data).then((r) => {
				if (r.code == 200) {
					this.showToast(this.$t('orderDetails.submitSucs') ,"/pages/order/myOrder")
				}
			})	
		},
		//打开密码框
		openModal() {
			this.payPwdPopShow = true;
		},
		payPwdPopFinish(val) {
			console.log(val);			
				this.$u.post(`/app/user/check/bank/password?password=${val}`).then((res) => {
					this.payPwdPopShow = false;
					this.confirmReceipt()
				}
				// ,(err)=>{
				// 	this.showToast(this.$t('orderDetails.notCorrectly'))
				// }
				);		
			
		},
		showToast(tittle,url) {
			this.$refs.uToast.show({
				title: tittle,
				type: 'default',
				url: url
			})
		}
	},
	onLoad(options) {
		
		this.type = options.type;
		this.goodsDetail = this.vuex_shoping_cartList;
		console.log(55555,this.goodsDetail);
			
		if(this.goodsDetail.platformReturnExpress){
			this.placeholder = this.goodsDetail.platformReturnExpress.express
			this.handleSearch()
		}else if(this.type==1){			
			this.placeholder = this.goodsDetail.userReturnExpress.expressNum
			this.handleSearch()		
		}
		// console.log(1111111111111111,this.goodsDetail);
		this.value2 = this.goodsDetail.returnInfo.type
	}
};
</script>

<style lang="scss" scoped>
	/deep/.pay-pwd-pop .popup-main .amount {
		display: none;
	}
	/deep/.u-input--border{
		border-radius: 20rpx ;
	}
/deep/.uni-scroll-view,
.uni-scroll-view-content {
	height: 92%;
}
.company{
	color: rgb(102, 102, 102);
	font-size:28rpx;
}
.fill-number{
	display: flex;
	justify-content: center;
	align-items: center;
}
.goodsInfo {
	border-bottom: 8rpx solid #f2f3f5;
	.productBox {
		background: #ffffff;
		border-radius: 26rpx 26rpx 26rpx 26rpx;
		opacity: 1;
		border: 1px solid #e1e8e8;
		margin: 40rpx;
		padding: 20rpx;

		.productBox_top {
			display: flex;
			padding-bottom: 10px;
			justify-content: space-between;
			.productBox-img {
				display: flex;
				.middle-box {
					width: 450rpx;
					padding-left: 20rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					.productBox-tittle {
						font-size: 30rpx;
						color: #000000;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					.productBox-introl {
						font-size: 24rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
					.number-box {
						display: flex;
						justify-content: space-between;
						.productBox-num {
							font-size: 30rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
							background-color: #dadada;
							border-radius: 12rpx;
							padding: 5rpx;
						}
						.productBox-price {
							font-size: 30rpx;
							color: #000000;
							font-weight: 500;
						}
					}
				}
			}
		}
	}
}
.cancle-box {
	padding: 48rpx 40rpx;
	font-size: 30rpx;
	font-family: SFUIDisplay-Medium-Regular, SFUIDisplay-Medium;
	font-weight: 400;
	color: #212121;
}
.tittle1{
	margin: 30rpx 0;
}

.control-button {
	width: 670rpx;
	height: 120rpx;
	font-size: 32rpx;
	position: absolute;
	bottom: 0rpx;
	right: 0;
	left: 0;
}
.u-toast {
	width: 450rpx;
	height: 100rpx;
}
.popop-box1{
	margin:20rpx 0;
}
</style>
